Skip to content

Feature/username edit #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jan 1, 2025
Merged

Feature/username edit #26

merged 31 commits into from
Jan 1, 2025

Conversation

tomast1337
Copy link
Member

This pull request includes adding a feature to update usernames.

User Management Enhancements:

  • Server-side updates:

    • Added a new UpdateUsernameDto for validating username updates (server/src/user/user.controller.ts, server/src/user/user.service.ts) [1] [2].
    • Introduced a new updateUsername method in UserController to handle PATCH requests for updating usernames (server/src/user/user.controller.ts).
    • Implemented updateUsername and normalizeUsername methods in UserService to handle username updates and normalization respectively (server/src/user/user.service.ts) [1] [2].
    • Added tests for normalizeUsername and updateUsername methods in UserService (server/src/user/user.service.spec.ts).
  • Client-side updates:

    • Created a new Axios client (ClientAxios) with an interceptor to add authorization tokens to requests (web/src/lib/axios/ClientAxios.ts). In the future, this client will be used for all requests to the server as it will automatically add the authorization token to the request headers.
    • Updated GenericModal to use TypeScript interfaces for props (web/src/modules/shared/components/client/GenericModal.tsx) [1] [2].
    • Added EditUsernameModal component to allow users to edit their username through a modal interface (web/src/modules/shared/components/layout/EditUsernameModal.tsx).
    • Integrated EditUsernameModal into the UserMenu component, allowing users to trigger the modal from their user menu (web/src/modules/shared/components/layout/UserMenu.tsx) [1] [2] [3].

Preview:

In the user menu, users can now click on the pen icon next to their username to open a modal where they can update their username.
UserMenu

The modal allows users to enter a new username and submit the form to update their username. The modal will display any errors that occur during the update process, such as an invalid username or a username that is already taken and throttling limits.
Dialog

Testing:

On the backend, I have added tests for the normalizeUsername and updateUsername methods in the UserService class.

I have concerns about whether non-ASCII characters should be allowed in usernames. Currently, they're not allowed, but it would be cool if they were.
And, we don't have a profanity filter for usernames, so we should consider adding one before allowing this feature to be used in production.

Bentroen and others added 26 commits December 20, 2024 02:01
The bad part about code is that it does exactly what you tell it to!
When not set in an environment variable, `COOKIE_EXPIRES_IN` will default to `60 * 60 * 24 * 7` = 604,800s = 7 days, since the `Max-Age` cookie attribute is specified in seconds:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#max-agenumber

However, the `res.cookie` function takes the `maxAge` **in milliseconds**. which means that the previous amount of seconds actually meant *604.8 seconds* ~= 10 minutes. Oof.
@tomast1337
Copy link
Member Author

About the profanity check

I was searching about it and I saw some node libraries like:

  • bad-words it seems to be very bad at what it does.
  • obscenity It seems to be better than it uses a good heuristic, but it supports only English, maybe it could be extended to support more languages.

I recalled Steam's profanity filter, was leaked I have a fork of it, here steam-profanity-filter it is a good profanity filter, it supports a lot of languages, but is only a regex like a word list.

@Bentroen
Copy link
Member

About the profanity check

...

We might get away without one for now, as song titles/descriptions have no profanity check either. Manual moderation may be enough for now until we can invest in better automated checks.

It's also far from a trivial problem, especially when multiple languages are involved. I took a look at some of the profanity word lists you sent for the Portuguese language and they're nowhere near as exhaustive as they could be – I could think of five words that weren't covered in the list in a not-so-long timespan. 😅

(For instance, there was once a problem with users not being able to rename an item to "Stone Hoe" in Minecraft Bedrock Edition, or "computador" being replaced with "com****dor", see Scunthorpe problem.)

@tomast1337
Copy link
Member Author

@Bentroen I merged your front-end changes from feat/username-change. I will take a look at the failing test to merge this branch

@tomast1337 tomast1337 merged commit 765fce8 into develop Jan 1, 2025
2 checks passed
@tomast1337 tomast1337 deleted the feature/username-edit branch January 1, 2025 01:14
@Bentroen
Copy link
Member

Bentroen commented Jan 1, 2025

Thanks for merging! Happy New Year! 🥂✨

I have concerns about whether non-ASCII characters should be allowed in usernames. Currently, they're not allowed, but it would be cool if they were.

Usernames are meant to be used in the URL slug for usernames in a future update, just like YouTube/TikTok user handles (i.e. https://noteblock.world/@Bentroen). I'm pretty sure those platforms restrict the characters that may be there to a small subset to keep the URLs uniform and easily typable. In fact the chosen characters (A-z 0-9 - _ .) are exactly what I recall YouTube uses in their new handles :)
Discord also not-so-recently shifted from username + 4-digit discriminator to a single username, that can only contain the aforementioned alphanumeric characters + a period (.) — in what I know was a quite controversial change, admittedly.

There's an additional concern with this: non-ASCII characters cannot be properly encoded in NBS files, and we currently inject the uploader's username into the 'Author' field of the song file. As such, we need the user to provide us an ASCII-safe string to use as their author name, because doing an 'educated guess' using unidecode could have a lot of bad implications, or even be outright offensive.

To circumvent this, we may implement a 'Display name' on the user profile that would be displayed in most places across the interface — which could be way less restrictive in terms of the allowed characters.

@Bentroen Bentroen linked an issue Jan 21, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No option to change your username
2 participants